﻿using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Entities;

namespace SqlSugarCore.Dal.BaseRealize
{
    /// <summary>
    /// 删除相关
    /// </summary>
    public partial class BaseDal<T> where T : class, new()
    {

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Delete(T entity)
        {
            var insertNum = this._sqlSugarClient.Deleteable<T>(entity).ExecuteCommand();
            return insertNum;
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<int> DeleteAsync(T entity)
        {
            var insertNum = await this._sqlSugarClient.Deleteable<T>(entity).ExecuteCommandAsync();
            return insertNum;
        }

        public int Delete(Expression<Func<T, bool>> expression)
        {
            var insertNum = this._sqlSugarClient.Deleteable<T>(expression).ExecuteCommand();
            return insertNum;
        }

        public async Task<int> DeleteAsync(Expression<Func<sys_user, bool>> expression)
        {
            var insertNum = await this._sqlSugarClient.Deleteable<T>(expression).ExecuteCommandAsync();
            return insertNum;
        }
    }
}